# This Python 3 environment comes with many helpful analytics libraries installed
# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python
# For example, here's several helpful packages to load
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
# Input data files are available in the read-only "../input/" directory
# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory
import os
for dirname, _, filenames in os.walk('/kaggle/input'):
for filename in filenames:
print(os.path.join(dirname, filename))
# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using "Save & Run All"
# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session
What are the three essential relations between the support, confidence and lift?
Given two Apps A1 and A2, here are the three essential relations to remember:
Relation between the support and the confidence: confidence(A1 -> A2) =support(A1,A2)/support(A1)
Relation between the lift and the support: lift(A1 -> A2) =support(A1,A2)/support(A1)*support(A2)
Relation between the lift and the confidence (consequence of the two previous equations): lift(A1 -> A2) =confidence(A1 -> A2)/support(A2)
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
dataset = pd.read_csv('/kaggle/input/apps-user-used-the-most/apriori_data.csv')
dataset
df = list(dataset["AppName"].apply(lambda x:x.split(',')))
dataset=pd.DataFrame(df)
#Displaying the First Five Rows
dataset.head()
#Displaying the last Five Rows
dataset.tail()
dataset.shape
dataset.dtypes
dataset.isnull().sum()
dataset.info()
dataset.to_csv('apps_dataset.csv',header=None,index=False)
dataset = pd.read_csv('./apps_dataset.csv', header = None)
transactions = []
for i in range(0, 31):
transactions.append([str(dataset.values[i,j]) for j in range(0, 10)])
dataset.head()
!pip install apyori
from apyori import apriori
rules = apriori(transactions=transactions, min_support = 0.03, min_confidence = 0.2, min_lift = 2, min_length = 2, max_length = 2)
results=list(rules)
results
def inspect(results):
App1 = [tuple(result[2][0][0])[0] for result in results]
App2 = [tuple(result[2][0][1])[0] for result in results]
Supports = [result[1] for result in results]
Confidences = [result[2][0][2] for result in results]
Lifts = [result[2][0][3] for result in results]
return list(zip(App1, App2,Supports, Confidences, Lifts))
final_result = pd.DataFrame(inspect(results), columns = ['App 1', 'App 2', 'Support', 'Confidence', 'Lift'])
final_result
final_result.nlargest(n = 10, columns = 'Lift')
final = final_result.rename({'App 1':'App1','App 2':'App2'}, axis=1)
final
plt.figure(figsize=(10,10))
sns.heatmap(data=final.corr(), annot=True, cmap='copper_r')
plt.scatter(final.App1,final.App2)
plt.xlabel('App 1')
plt.ylabel('App 2')
plt.title('App Recommended')